import fileinput

outfile = open('D:\\adservers.txt', "w")
for line in fileinput.input(['D:\\adhosts.txt']):
       try:
             if line.startswith("#"): 
                 continue
             fields=line.split()
             outfile.write(fields[1]+'\n')
       except:
        
            continue